/*************************全局变量****************************************/
GLOBAL = {}
//GLOBAL.URL = 'http://cbmobile.frpgz1.idcfengye.com';
GLOBAL.URL = 'https://www.slivercloud.cn/chinamobile';
//GLOBAL.URL="http://cbmobile.frpgz1.idcfengye.com"
//GLOBAL.URL='http://ng.slivercloud.cn:8084';
//GLOBAL.URL = 'http://192.168.2.117';
GLOBAL.IMGURL = '';
GLOBAL.deptId=0;
GLOBAL.userId=0;
GLOBAL.area="绵阳市";
GLOBAL.USERNAME="";
GLOBAL.MODULEURL = 'Page/Panorama/index.html';
GLOBAL.LOADURl = 'Page/Panorama/map/map.html';

//路由跳转
function loadcenterurl(id, url, callback) {
	$(id).empty();
	$(id).load(url, function() {
		if(typeof callback == "function") {
			callback();
		}
	});
}

//退出
function OutSystem() {
	window.location.href = "login.html";
}

//function EditPassWord(){
//	GLOBAL.LOADURl = "Page/system/systeamuser/index.html";
//	SaveDialog("#EditPAssWord", "Page/EditPassWord.html", "/sys/user/save", "修改密码");
//}

//点击菜单
function CheckMenu(url) {
	loadcenterurl("#main", url);
}

//新增编辑弹窗
function SaveDialog(Id, Url, action, title, callbackfuc) {
	var str = '<div class="md-content">' +
		'<h7>' + title + '</h7>' +
		'<div id="Content" style="border-top:1px solid #d7d6d6;margin-top:10px;"></div>' +
		'<div class="md-Button"><button class="btn btn-danger close_button md-footer-Button" onclick=CloseDialog()>取消</button><button class="btn btn-primary md-footer-Button"  onclick=Save("' + Id + '","' + action + '")>确定</button></div>' +
		'</div>';
	$("#EditDialog").html(str);

	var doc = document.documentElement;
	relHeight = (doc.clientHeight > doc.scrollHeight) ? doc.clientHeight : doc.scrollHeight; //获取屏幕高度和当前页面高度中的较大值
	document.getElementById("MainContent").style.height = relHeight + 'px'; //id为bg的div就是我页面中的遮罩层
	$("#EditDialog").addClass("md-show");
	$("#MainContent").show();
	$("#Content").load(Url, function(data, rec) {
		if(typeof callbackfuc == "function") {
			callbackfuc();
		}
	});
}

//关闭弹窗
function CloseDialog(Id) {
	$("#EditDialog").removeClass("md-show");
	$("#MainContent").hide();
}

//确定按钮
function Save(Id, action) {
	var num = Math.random();
	$(Id).ajaxSubmit({
		url: GLOBAL.URL + action + "?" + num,
		type: 'POST',
		dataType: "json",
		ContentType: 'application/json',
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(msg) {
			if(msg.code == "0") {
				AlertInfo("操作成功！");
				$("#MainContent").hide();
				$("#EditDialog").removeClass("md-show");
				getdata(1);
			} else if(msg.code == "403") {
				AlertInfo("操作失败！" + msg.msg);
				window.location.href = "login.html";
			} else {
				AlertInfo("操作失败！" + msg.msg);
			}
		}
	});
}

//新增编辑弹窗
function SaveDialogMiddle(Id, Url, action, title, callbackfuc) {
	var str = '<div class="md-content">' +
		'<h7>' + title + '</7>' +
		'<div id="ContentMiddle"  style="border-top:1px solid #d7d6d6;margin-top:10px;"></div>' +
		'<div class="md-Button"><button class="btn btn-primary md-footer-Button"  onclick=SaveMiddle("' + Id + '","' + action + '")>确 定</button><button class="btn btn-danger close_button md-footer-Button" onclick=CloseDialogMiddle()>取 消</button></div>' +
		'</div>';
	$("#EditDialogMiddle").html(str);

	var doc = document.documentElement;
	relHeight = (doc.clientHeight > doc.scrollHeight) ? doc.clientHeight : doc.scrollHeight; //获取屏幕高度和当前页面高度中的较大值
	document.getElementById("MainContent").style.height = relHeight + 'px'; //id为bg的div就是我页面中的遮罩层
	$("#EditDialogMiddle").addClass("md-show");
	$("#MainContent").show();
	$("#ContentMiddle").load(Url, function(data, rec) {
		if(typeof callbackfuc == "function") {
			callbackfuc();
		}
	});
}

//关闭弹窗
function CloseDialogMiddle(Id) {
	$("#EditDialogMiddle").removeClass("md-show");
	$("#MainContent").hide();
}

//确定按钮
function SaveMiddle(Id, action) {
	var num = Math.random();
	$(Id).ajaxSubmit({
		url: GLOBAL.URL + action + "?" + num,
		type: 'POST',
		dataType: "json",
		ContentType: 'application/json',
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(msg) {
			if(msg.code == "0") {
				AlertInfo("操作成功！");
				$("#MainContent").hide();
				$("#EditDialogMiddle").removeClass("md-show");
				getdata(1);
			} else if(msg.code == "403") {
				AlertInfo("操作失败！" + msg.msg);
				window.location.href = "login.html";
			} else {
				AlertInfo("操作失败！" + msg.msg);
			}
		}
	});
}


//图片弹窗
function ImageDialog(url) {
	var str = '<div class="md-content">' +
		'<div id="Content" style="width:830px;height:500px;">'+
		'<div style=" position: absolute;top: 5px;right: 5px;"><i class="fa fa-times" onclick="CloseIamge()" style="width:25px;height:25px;cursor: pointer;font-size:25px;color:#999"></i></div>'+
		'<img src="'+url+'" style="display: inline-block;" width="100%" height="100%" />'+
		'</div>' +
		'</div>';
	$("#ImgMiddle").html(str);
	$("#ImgMiddle").addClass("md-show");
}
//关闭弹窗
function CloseIamge(Id) {
	$("#ImgMiddle").removeClass("md-show");
	$("#MainContent").hide();
}


//发现新版本
//function AjaxTodayProduct() {
//		var json = {
//			"url": GLOBAL.URL + "/product/todayHot",
//			"type": 'get',
//			"successfn": function(data) {
//				UpdateTodayProduct(data.list);
//			},
//			"errorfn": function() {
//				//ajaxUpdataTable();
//				//$.ligerDialog.warn("系统繁忙，请稍候再试");
//			}
//		};
//		vbolyajax(json);
//	}

//ajax请求
function ajaxdata(json) {
	var num = Math.random();
	$.ajax({
		type: json.type, //请求的类型
		url: json.url + "?" + num, //请求的地址
		data: json.data, //发送服务器的数据
		dataType: "json", //返会值的类型
		async: false,
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(datas, textStatus) { //请求成功执行的代码
			if(datas.code == 0) {
				json.successfn(datas);
			} else if(datas.code == 403) {
				AlertInfo("操作失败！" + datas.msg);
				window.location.href = "login.html";
			} else {
				var msg = datas.msg == null ? "" : datas.msg;
				AlertInfo("请求失败！" + msg);
			}
		},
		error: function() {
			json.errorfn();
		}

	});
}

//单次单选弹框
function AlertInfo(info) {
	var onlyChoseAlert = simpleAlert({
		"content": info,
		"buttons": {
			"确定": function() {
				onlyChoseAlert.close();
			}
		}
	})
}

//单次双选弹框
function AlertDel(del, ID) {
	var dblChoseAlert = simpleAlert({
		"title": "提示",
		"content": "确定删除该数据吗？",
		"buttons": {
			"取消": function() {
				dblChoseAlert.close();
			},
			"确定": function() {
				del(ID, dblChoseAlert);
			}
			
		}
	})
}

//form表单加载
function loadForm(id, url) {
	var num = Math.random();
	$.ajax({
		type: "GET",
		url: GLOBAL.URL + url + "?" + num,
		dataType: "json",
		cache: false,
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(editData) {
			$(id).fill(editData.info);
		}
	});
}

//分页
var oldpage=0;
function setPage(pages) {
	$("#page").whjPaging({
		css: 'css-2',
		isShowPageSizeOpt: false,
		totalPage: pages,
		isResetPage: true,
		isShowRefresh: false,
		isShowTotalPage: true,
		callBack: function(currPage, pageSize) {
			getdata(currPage);
			
			$("#page").whjPaging("setPage", currPage, oldpage);
		}
	});
	$("#page").whjPaging("setPage", 1, pages);
    oldpage=pages;
}

//修改密码 
function EditPassWord(){
	var node=$('.nav>li');
	for(var i=0;i<node.length;i++){
		if(i==node.length-1){
			node[i].style.borderBottom= "3px solid #4dc765";
		}else{
			node[i].style.borderBottom="none";
		}
	}
	
	loadcenterurl("#main", 'Page/system/index.html',function(){
			tab('tabId5','Page/system/EditPassWord.html','修改密码');
	});
}
